import { defineStore } from 'pinia'

export const useMyStore = defineStore('myStore', {
  state: () => {
    return {
      router: '',
      params: {}, // 请求参数
      user: {},
      token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzIiwiZXhwIjoxNzI5NzcxMDMyLCJzdWIiOiJzdGFmZjMiLCJpYXQiOjE3MjkxNjYyMzJ9.6BNo8dPWJWGw93IXARyN5pUrTZXref1qWmQNbviCOLs'
    }
  },
  actions: {
    login(user: any) {
      this.$patch({
        user: user
      });
      localStorage.setItem('vuser', JSON.stringify(user));
    },
    logout() {
      this.$patch({
        user: {}
      })
      localStorage.removeItem('vuser');
    }
  },
  persist: true
})